package com.aspose.cells.b.a.g;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;

public class zb {
   private CharsetDecoder b;
   private int c = 0;
   private byte[] d;

   public zb(Charset var1) {
      this.b = var1.newDecoder().onMalformedInput(CodingErrorAction.REPLACE).onUnmappableCharacter(CodingErrorAction.REPLACE);
   }

   public int a(byte[] var1, int var2, int var3, char[] var4, int var5) throws CharacterCodingException {
      if (var4 != null && var1 != null) {
         if (var3 >= 0 && var5 >= 0) {
            if (var5 <= var4.length && var3 >= 0 && var3 <= var1.length + var2) {
               int var6 = var4.length - var5;
               CharBuffer var7 = CharBuffer.wrap(var4, var5, var6);
               ByteBuffer var8;
               if (this.c > 0) {
                  var8 = ByteBuffer.allocate(this.c + var3 - var2);
                  var8.put(this.d);
                  var8.put(var1, var2, var3);
                  var8.rewind();
                  this.d = null;
               } else {
                  var8 = ByteBuffer.wrap(var1, var2, var3);
               }

               CoderResult var9 = this.b.decode(var8, var7, false);
               this.c = var8.remaining();
               if (this.c > 0) {
                  this.d = new byte[this.c];
                  var8.get(this.d);
               }

               int var10;
               if (var9.isError()) {
                  var10 = var9.length();
                  this.d = new byte[var10];
                  var8.position(var8.position() - var10);
                  var8.get(this.d);
                  this.c = var10;
               }

               if (var9.isOverflow()) {
                  throw new IllegalArgumentException("Decode Overflow: insufficient space in the 'chars' array.");
               } else {
                  var10 = var6 - var7.remaining();
                  return var10;
               }
            } else {
               throw new IndexOutOfBoundsException(var5 > var4.length ? "charIndex" : "byteCount");
            }
         } else {
            throw new IndexOutOfBoundsException(var3 < 0 ? "byteCount" : "charIndex");
         }
      } else {
         throw new NullPointerException(var4 == null ? "chars" : "bytes");
      }
   }

   public int a(int var1) {
      assert var1 >= 0;

      return (int)((double)this.b.maxCharsPerByte() * (double)var1);
   }
}
